################################################################################
################################################################################

function distance = euclidean_distance(vector_1, vector_2)
    sum_sum = 0.0;
    for i = 1 : columns(vector_1)

        sum_sum = sum_sum + (vector_1(i) - vector_2(i))^2;
    endfor

    distance = sqrt(sum_sum);
endfunction

################################################################################
## calculates the generation distance using p = 2                             ##
##                                                                            ##
################################################################################
function distance = generation_distance(real_pareto_front, pareto_front)
    sum_d_i = 0;
    for i = 1 : rows(pareto_front)
        fprintf(stderr, "evaluating generation distance ... %d/%d\r",i, rows(pareto_front));
        d_i = realmax;
        for j = 1 : rows(real_pareto_front)
            distance = euclidean_distance(real_pareto_front(j, :),
                                                pareto_front(i, :));
            if (distance < d_i)
                d_i = distance;
            endif
        endfor
        sum_d_i = sum_d_i + d_i^2;
    endfor
    fprintf(stderr, "evaluating generation distance ...   [done]\n");
    distance = 1/rows(pareto_front) * (sum_d_i^(1/2));
endfunction
